package net.jdm.constraint.dependence;

import java.util.Set;
import java.util.regex.Matcher;

import net.jdm.common.Alert;
import net.jdm.common.Alert.DetailLevel;
import net.jdm.constraint.PrintSupport;
import net.jdm.constraint.dependence.DependenceConstraint.DependenceConstraintType;
import net.jdm.domain.dependence.ContainerDependence;
import net.jdm.domain.dependence.PackageDependence;

/**
 * @author wang.li
 *
 */
public final class PackageDependencePrinter implements DependencePrinter{
	private final PrintSupport printSupport=PrintSupport.getInstance();
	private static PackageDependencePrinter printer=new PackageDependencePrinter();
	private PackageDependencePrinter(){}
    public static PackageDependencePrinter getInstance(){
          return printer;
    }
	@Override
	public void printViolationDependences(Alert alert,String scopeName,
			DependenceConstraintType dependenceConstraintType,
			Set<DependenceDefine> definedDependences,
			Set<? extends ContainerDependence> violationDependences) {
		String message = alert.getAlertMessage()
		.replaceAll("\\\\n", "\\" + printSupport.separator)
		.replaceAll("\\$\\{component\\}", scopeName)
		.replaceAll("\\$\\{type\\}", dependenceConstraintType.name())
		.replaceAll("\\$\\{dependences\\}",printSupport.getCollectionString(definedDependences))
		.replaceAll("\\$\\{detail\\}",Matcher.quoteReplacement(printSupport.getPackageDependencesDetail((Set<PackageDependence>)violationDependences,alert.getDetailLevel()!=DetailLevel.LOW)));
         alert.getAlertLevel().print(message);
	}
}
